package com.ky.serialport.sensor;

import com.ky.serialport.bean.ComBean;
import com.ky.serialport.utils.MyFunc;

import static com.ky.serialport.utils.RandomUtils.myRandom;

/**
 * 温度传感器解析对象
 */
public class WenDuBean {

    byte[] bRec;
    public Long time;
    public float wenduVel; //温度
    public int power; // 电量
    public int signal; //信号
    public ComBean comBean;

    public WenDuBean() {

    }

    public WenDuBean(ComBean comBean ) {
        caculate(comBean.recData);
        time = comBean.recTime;
        this.comBean = comBean;
    }

    public WenDuBean(byte[] recData) {
        caculate(recData);
        time = System.currentTimeMillis();
    }

    public WenDuBean caculate(ComBean comBean){
        time = comBean.recTime;
        return caculate(comBean.recData);
    }


    public WenDuBean caculate(byte[] bRec) {
        wenduVel = (float) MyFunc.twoByte2IntNoSign(bRec[14], bRec[15]) / 100;
        power = MyFunc.getPower(bRec[16],bRec[17]);
        signal = MyFunc.getSignal(bRec[18]);
        return this;
    }

    public WenDuBean test() {
        time = System.currentTimeMillis();
        power = 300 + myRandom.nextInt(120);
        signal = 200;
        wenduVel =  20 + myRandom.nextInt(5);
        return this;
    }

}
